/**
 * JSON转换工具（原生）
 *
 * 摘自腾讯qq第三方登录SDK qc_loader.js
 */
var $JSON = function() {
    var escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g
      , meta = {
        '\b': '\\b',
        '\t': '\\t',
        '\n': '\\n',
        '\f': '\\f',
        '\r': '\\r',
        '"': '\\"',
        '\\': '\\\\'
    };
    function quote(string) {
        escapable.lastIndex = 0;
        return escapable.test(string) ? '"' + string.replace(escapable, function(a) {
            var c = meta[a];
            return typeof c === 'string' ? c : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
        }) + '"' : '"' + string + '"';
    }
    function stringify(obj) {
        var ret = []
          , v = "";
        for (var i in obj) {
            v = obj[i];
            v = v !== undefined ? v : "";
            switch (typeof v) {
            case 'string':
                v = quote(v);
                break;
            case 'object':
                v = stringify(v);
                break;
            case 'function':
                continue;
            }
            ret.push('"' + i + '":' + v);
        }
        return '{' + ret + '}';
    }
    return {
        stringify: function() {
            return window.JSON && JSON.stringify ? JSON.stringify : stringify
        }(),
        parse: function(str) {
            str = str || "{}";
            var ret = {};
            try {
                ret = (new Function("return (" + str + ")"))();
            } catch (e) {
                $Console.error("JSON.parse => parse数据格式错误:" + str);
            }
            return ret;
        }
    }
}();